package ex402;

import ex402.exercise.AdditionExercise;
import ex402.exercise.AdditionQuestion;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("输入加法练习的题目数量: ");
        int n = input.nextInt();
        System.out.print("输入加法练习的加数范围的最小值: ");
        int min = input.nextInt();
        System.out.print("输入加法练习的加数范围的最大值: ");
        int max = input.nextInt();

        AdditionExercise exercise = new AdditionExercise();
        exercise.generateQuestions(n, min, max);

        System.out.printf("本次练习共有%d个题目.\n", exercise.getNumberOfQuestions());
        for (int index = 0; index < exercise.getNumberOfQuestions(); index++) {
            AdditionQuestion question = exercise.getQuestion(index);
            System.out.printf("题目%d: %s, 输入你的答案: ", index + 1, question);
            int userAnswer = input.nextInt();
            question.setUserAnswer(userAnswer);
            System.out.println(question.judge() ? "正确" : "错误");
        }

        System.out.printf("一共做对了 %d 个题目！\n", exercise.getNumberOfCorrect());

    }

}
